package com.atguigu.gmall.all.controller;

import com.atguigu.gmall.model.user.UserAddress;
import com.atguigu.gmall.order.client.OrderFeignClient;
import com.atguigu.gmall.user.client.UserFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;
import java.util.Map;

/**
 * @Author: 李旭
 * @Time: 11:22
 * @Description:
 *
 * 订单管理
 */
@Controller
public class OrderController {

    @Autowired
    private UserFeignClient userFeignClient;
    @Autowired
    private OrderFeignClient orderFeignClient;
    //去结算  入参 用户ID
    @GetMapping("/trade.html")
    public String trade(Model model){

        //1:根据用户ID 查询收货地址集合    来源于用户微服务
        List<UserAddress> userAddressList = userFeignClient.userAddressList();
        model.addAttribute("userAddressList",userAddressList);
        //2:交易号  订单号  防止幂等性问题   防止生成二张订单  来源订单微服务
        //3:商品清单   来源购物车微服务
        Map<String, Object> trade = orderFeignClient.trade();
        //判断是否为NULL
        if(null == trade){
            return "redirect:http://cart.gmall.com/cart.html";
        }
        model.addAllAttributes(trade);
        return "order/trade";
    }
}
